// upload.js
const multer = require("multer");
const path = require("path");

// 配置存储路径和文件名
const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, path.join(__dirname, "../uploads/blogs")); // 上传到 uploads/blogs 目录
  },
  filename: function (req, file, cb) {
    const ext = path.extname(file.originalname); // 获取后缀名
    const filename = Date.now() + "-" + Math.round(Math.random() * 1e9) + ext;
    cb(null, filename);
  },
});

const upload = multer({ storage });

module.exports = upload;
